package com.swas.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.swas.entity.BaseStock;
import com.swas.service.BaseStockService;
import com.swas.util.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/basestock")
public class BaseStockController {
    @Autowired
    private BaseStockService baseStockService;

    @GetMapping("/findAll")
    //展示所有设备按条件查询
    public ResultVO findAll(Integer pageIndex, Integer pageSize, @RequestBody BaseStock baseStock){

        PageHelper.startPage(pageIndex,pageSize);
        List<BaseStock> list = baseStockService.findAll();
        PageInfo<BaseStock> pageInfo = new PageInfo<>(list);
        return ResultVO.success("ok",pageInfo);
    }


    @GetMapping("/findMenu")
    //查询目录
    public ResultVO findMenu(){
        List<BaseStock> list = baseStockService.findAll();
        return ResultVO.success("ok",list);
    }

    @GetMapping("/add")
    public ResultVO add(@RequestBody BaseStock baseStock ){
        boolean flag = baseStockService.add(baseStock);
        if (flag){
            return ResultVO.success("新增成功");
        }else {
            return ResultVO.fail("新增失败");
        }
    }

    @GetMapping("/update")
    public ResultVO update(@RequestBody BaseStock baseStock){
        boolean flag = baseStockService.update(baseStock);
        if (flag){
            return ResultVO.success("修改成功");
        }else {
            return ResultVO.fail("修改失败");
        }
    }

    @GetMapping("/delect")
    public ResultVO delect(@PathVariable("id") Integer id){
        boolean flag = baseStockService.delect(id);
        return ResultVO.success("删除成功");
    }
}
